package com.example.demo.mapper;

import com.example.demo.model.entity.Activity;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface ActivityMapper {

    @Insert("insert into activity (name, start_time, end_time, chance)" +
            " values (#{name}, #{startTime}, #{endTime}, #{chance})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insert(Activity activity);

    @Result(property = "prizeNumber", column = "number")
    @Select("select * from activity where name = #{name} limit 1")
    Activity selectByName(String name);

    @Select("select count(*) from activity")
    long getCount();

    @Select("select * from activity limit #{offset}, #{limit}")
    List<Activity> pageQuery(int limit, int offset);

    @Select("select * from activity where id = #{activityId}")
    Activity selectById(int activityId);

    @Delete("delete from activity where id = #{activityId}")
    void delete(int activityId);

    @Update("update activity set name = #{name}, start_time = #{startTime}, end_time = #{endTime}, chance = #{chance} where id = #{id}")
    void update(Activity activity);
}
